
import MockAdapter from "axios-mock-adapter";
import axios from "axios";
import {LoginUsers} from "./data/user";

//
export default {

    init() {
        let mock = new MockAdapter(axios)
        mock.onPost('/user/login').reply(arg => {
            console.log(LoginUsers)
            let { username, password } = JSON.parse(arg.data)
            return new Promise((resolve) => {
                let token = null
                let hasUser = LoginUsers.some(u => {
                    if (u.username === username && u.password === password) {
                        token = 'adminXXXXXX'
                        return true
                    }
                })
                if (hasUser) {
                    resolve([200, { code: 200, msg: '请求成功', token: token }])
                } else {
                    resolve([200, { code: 500, msg: '账号或密码错误' }])
                }
            })
        })



    }

}
